package com.software_product_construction.backend_software_product_construction.controller;

import com.software_product_construction.backend_software_product_construction.pojo.Respondent;
import com.software_product_construction.backend_software_product_construction.pojo.User;
import com.software_product_construction.backend_software_product_construction.service.RespondentService;
import com.software_product_construction.backend_software_product_construction.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    RespondentService respondentService;

    @ResponseBody
    @RequestMapping("/getAnswerList")
    private List<Respondent> findAll(@RequestParam(defaultValue = "") String account, @RequestParam(defaultValue = "cad34900-99da-c193-4a24-34b7fb97626b") String userId,
                         @RequestParam(defaultValue = "2") int from, @RequestParam(defaultValue = "10") int to
                         ){
        System.out.println("user/getAnswerList");
        List<Respondent> list = respondentService.findAll(account,userId,from,to);
        System.out.println(list);
        return list;
    }

    @RequestMapping("/deleteAnswerById")
    public String deleteAnswerById(@RequestParam(defaultValue = "00085edc-e6df-23d9-76cf-2005f4991e70") String id){
        return respondentService.deleteById(id);
    }

    @RequestMapping("/modifyPersonalInfo")
    public String modifyPersonalInfo(@RequestParam User  user){
        return userService.update(user);
    }

    @ResponseBody
    @RequestMapping("/getLesseePersonalHistory")
    public List<User> getLesseePersonalHistory(@RequestParam(defaultValue = "00069bd7-453a-9e1a-14eb-37262e87a785" )String userId,
            @RequestParam(defaultValue = "1") int from,@RequestParam(defaultValue = "10") int to){

        List<User> list = userService.getHistory(userId,from,to);

        System.out.println(list);
        return list;
    }

}
